package cn.tedu.micro.demo.topic;

import cn.tedu.micro.demo.client.RabbitChannelManager;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import org.junit.Test;

public class TopicDemo {

    @Test
    public void declareDirect() throws Exception {
        //1.拿到客户端
        Channel channel= RabbitChannelManager.newChannel();
        //删除清空队列
        channel.queueDelete("queue1");
        channel.queueDelete("queue2");
        channel.queueDelete("queue3");
        //2.声明3个队列
        channel.queueDeclare("queue1", false, false, false, null);
        channel.queueDeclare("queue2", false, false, false, null);
        channel.queueDeclare("queue3", false, false, false, null);
        //3.声明一个主题交换机
        channel.exchangeDeclare("topic_ex", BuiltinExchangeType.TOPIC);
        //4.声明绑定关系 上海 北京 天津
        channel.queueBind("queue1","topic_ex","中国.北京.朝阳");
        channel.queueBind("queue2","topic_ex","*.上海.*");
        channel.queueBind("queue3","topic_ex","中国.#");
    }
}